﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Basic global alias for the main class containing constants
using r = Rougeliek.Rougeliek;

namespace Rougeliek
{
    class Player
    {
        // Declare sumdat shit, woah yeah
        public int hp, maxhp, mp, maxmp, x, y, strength, agility, magic, stamina;
        public char sprite = '☺';

        public void playerSpawn()
        {
            // Set the players health and mana
            strength = 5;
            agility = 5;
            magic = 5;
            stamina = 5;
            hp = calcHealth(stamina);
            maxhp = calcHealth(stamina);
            mp = calcMana(magic);
            maxmp = calcMana(magic);

            // Initialise some random numbers
            Random rdmpcx = new Random();
            Random rdmpcy = new Random();

            // Set the player's initial coordinates to a random position based on the screen size
            x = rdmpcx.Next(r.SCREENMIN, r.SCREENX);
            y = rdmpcy.Next(r.SCREENMIN, r.SCREENY);
        }

        public int calcHealth(int tempStam)
        {
            int tempHP;

            tempHP = tempStam * 7;

            return tempHP;
        }

        public int calcMana(int tempMagic)
        {
            int tempMP;

            tempMP = tempMagic * 12;

            return tempMP;
        }

        public void playerMove(string direction)
        {
            // Variables to store the player's current position before a move is made,
            // which will be fed, on move, to the drawBufferTile function to refresh
            // position and remove past position
            int tempX = x;
            int tempY = y;

            // Check map boundary then collisions before moving the player
            if (direction == "N" && y > r.SCREENMIN && Map.checkCollision(x, y - 1) == false)
            {
                y--;
                ScreenBuffer.drawBufferTile(tempX, tempY);
            }
            else if (direction == "E" && x < r.SCREENX && Map.checkCollision(x + 1, y) == false)
            {
                x++;
                ScreenBuffer.drawBufferTile(tempX, tempY);
            }
            else if (direction == "S" && y < r.SCREENY && Map.checkCollision(x, y + 1) == false)
            {
                y++;
                ScreenBuffer.drawBufferTile(tempX, tempY);
            }
            else if (direction == "W" && x > r.SCREENMIN && Map.checkCollision(x - 1, y) == false)
            {
                x--;
                ScreenBuffer.drawBufferTile(tempX, tempY);
            }
        }


    }
}
